<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval( getvar( "gametype" ) );
$chk = new CheckMode_3d( $curruser['acl'], 5, $gametype );
$chk->checkShow3dPage();
if ( $g_gametype_3d[$gametype]['type'] == 3 )
{
    $betname_5h = $g_betname_5h[$gametype];
    $_5hFlag = true;
}
else
{
    $betname_5h = judge_type( $gametype );
    $_5hFlag = false;
}
unset( $chk );
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
include( "class_5h/Amounts_5h.php" );
$ui = new UI_3D();
$conf = new Config();
$tpl = new Template2();
$user = new User();
$Amounts_5h = new Amounts_5h( $gametype );
$curruser_p = user::getuser( $curruser['id'], $gametype );
$editportmod = intval( $conf->get( "editportmod_{$tbl}" ) );
$autorate_mode = intval( $conf->get( "autoportmod_{$tbl}" ) );
$editmode = 0;
$psen_edit_mod = 1;
$lotto_id = 0;
$startbet = $conf->get( "startbet_{$tbl}" );
$stopbet = $conf->get( "stopbet_{$tbl}" );
$nextDateFlag = false;
if ( $stopbet < $startbet )
{
    $nextDateFlag = true;
}
$now = date( "Hi" );
$todayTime = systime();
if ( $nextDateFlag && $now < $stopbet )
{
    $today = date( "Y-m-d", strtotime( "-1 day" ) );
}
else
{
    $today = date( "Y-m-d" );
}
$rs = getdb( "select open,id from lotto_{$tbl} where open>='{$today}' order by id ASC LIMIT 0,1" );
if ( !$rs->eof )
{
    $open = $rs->f['open'];
    $lotto_id = $rs->f['id'];
    $rs->close();
    if ( $today == $open )
    {
        if ( $nextDateFlag )
        {
            $addMin = 86460;
        }
        else
        {
            $addMin = 60;
        }
        $stoptime = $open." ".substr( $stopbet, 0, 2 ).":".substr( $stopbet, 2, 2 ).":00";
        $stopInt = strtotime( $stoptime ) + $addMin;
        $starttime = $open." ".substr( $startbet, 0, 2 ).":".substr( $startbet, 2, 2 ).":00";
        $startInt = strtotime( $starttime );
        if ( $startInt <= $todayTime && $todayTime <= $stopInt )
        {
            $psen_edit_mod = $editportmod;
        }
    }
}
$users = GetUserList( $curruser['id'] );
if ( $users != "" && 0 < $lotto_id )
{
    $rs = getdb( "select sum(amount) from bet_{$tbl} where user_id in ({$users}) and lotto_id>={$lotto_id} and rame=0" );
    if ( $rs->f[0] + 0 == 0 )
    {
        $psen_edit_mod = 1;
    }
    else
    {
        $psen_edit_mod = 0;
    }
    $rs->close();
}
if ( getvar( "chgpasswd" ) != "" )
{
    if ( $user->ChangePassword( getvar( "chgpasswd" ) ) == false )
    {
        $tpl->set( "msg", L_CHGPWDFAIL );
    }
    else
    {
        $tpl->set( "msg", L_CHGPWDSUCC );
    }
}
$theacl = $curruser['acl'];
$tpl->load( array( "main" => "info_3d.htm" ) );
$tpl->set( "account", $curruser['account'] );
$tpl->set( "name", $curruser['name'] );
$tpl->set( "amount", number_format( $curruser['amount'] ) );
$percent = 1;
if ( $theacl == 2 )
{
    $percent = $curruser_p['mpercent'];
    $tpl->set( "percent", "<tr><td class=\"title0 bgImg_{$gametype}\">占成<td class=td2>{$percent}%" );
}
$protmod = 0;
if ( 0 < $autorate_mode )
{
    if ( $theacl == 2 )
    {
        $u_genagent = get_user( $curruser['prev_id'], $gametype );
        $u_shareowner = get_user( $u_genagent['prev_id'], $gametype );
        $u_subsidary = get_user( $u_shareowner['prev_id'], $gametype );
        $protmod = $u_subsidary['protmod'];
    }
    else if ( $theacl == 3 )
    {
        $u_shareowner = get_user( $curruser['prev_id'], $gametype );
        $u_subsidary = get_user( $u_shareowner['prev_id'], $gametype );
        $protmod = $u_subsidary['protmod'];
    }
    else if ( $theacl == 4 )
    {
        $u_subsidary = get_user( $curruser['prev_id'], $gametype );
        $protmod = $u_subsidary['protmod'];
    }
    else if ( $curruser_p['percent_sw'] == 1 )
    {
        $protmod = 0;
        $psen_edit_mod = 0;
    }
    else
    {
        $protmod = $curruser_p['protmod'];
    }
}
if ( 0 < $psen_edit_mod && 0 < $protmod && isset( $_POST['auto_ok'] ) )
{
    foreach ( $betname_5h as $key => $value )
    {
        if ( isset( $_POST["autont".$key] ) )
        {
            $auto_nt = intval( $_POST["autont".$key] );
            $auto_ntOld = intval( $_POST["autont".$key."old"] );
            if ( $auto_nt != $auto_ntOld )
            {
                $bettypeArr = array( $key, 0 );
                $sql = "update amounts_{$tbl} set auto_nt=".$auto_nt." ,updateid=".$curruser['id']." ,updatedt='".date( "Y-m-d H:i:s" )."' where user_id=".$curruser['id']." and bettype=".$bettypeArr[0]." and subid=".$bettypeArr[1]."";
                getdb( $sql );
            }
        }
    }
}
$list = "";
$rs = $Amounts_5h->getAmountsRsById( $curruser['id'] );
$chk_autont = 0;
while ( !$rs->eof )
{
    if ( $_5hFlag )
    {
        $array = $betname_5h[$rs->f['bettype']];
    }
    else
    {
        $array = $betname_5h[$rs->f['bettype']."_".$rs->f['subid']];
    }
    $tempIdx = $rs->f['bettype'];
    if ( isset( $array ) )
    {
        $list .= "<tr class=\"td2\">";
        $list .= "<td nowrap class=\"td17\">".$array."</td>";
        if ( $rs->f['amount2'] == 0 )
        {
            $list .= "<td nowrap align=\"right\"> - </td>";
            $list .= "<td nowrap align=\"right\"> - </td>";
            $list .= "<td nowrap align=\"right\"> - </td>";
        }
        else
        {
            $list .= "<td nowrap align=\"right\">".round( 100 - $rs->f['back1'], 2 )."</td>";
            $list .= "<td nowrap align=\"right\">".round( 100 - $rs->f['back2'], 2 )."</td>";
            $list .= "<td nowrap align=\"right\">".round( 100 - $rs->f['back3'], 2 )."</td>";
            $list .= "<td nowrap align=\"right\">".round( 100 - $rs->f['back4'], 2 )."</td>";
            $list .= "<td nowrap align=\"right\">".number_format( $rs->f['amount2'] )."</td>";
            $list .= "<td nowrap align=\"right\">".number_format( $rs->f['amount1'] )."</td>";
            if ( 0 < $protmod )
            {
                if ( 0 < $psen_edit_mod )
                {
                    $list .= "<td nowrap align=\"right\"><input type=\"hidden\" value=\"".$rs->f['auto_nt']."\" name=\"autont".$tempIdx."old\" size=\"6\" style=\"text-align:right\" /><input type=\"text\" value=\"".$rs->f['auto_nt']."\" name=\"autont".$tempIdx."\" size=\"6\" style=\"text-align:right\" /></td>";
                }
                else
                {
                    $list .= "<td nowrap align=\"right\">".$rs->f['auto_nt']."</td>";
                }
                $list .= "<td nowrap align=\"right\">".$rs->f['updatedt']."</td>";
            }
        }
        $list .= "</tr>";
        ++$chk_autont;
    }
    $rs->movenext();
}
if ( $list == "" )
{
    $list = "<tr class=\"row1\"><td colspan=\"7\">查无资料</td></tr>";
}
if ( $autorate_mode && 0 < $chk_autont && 0 < $protmod )
{
    $tpl->set( "tableexc1", "<td class=\"title0 bgImg_{$gametype}\" width='14%'>自动走飞设定</td>" );
    $tpl->set( "tableexc2", "<td class=\"title0 bgImg_{$gametype}\" width='22%'>最後修改的日期 时间</td>" );
    if ( 0 < $psen_edit_mod && $autorate_mode )
    {
        $tpl->set( "rottexc", "<font color=red>※ 自动走飞金额为 0 代表该项目不启动自动走飞！</font>" );
        $tpl->set( "btnsubmit", "<input type=submit value=确定>" );
        $list .= "<input type=hidden name=auto_ok value=1>";
    }
    else
    {
        $tpl->set( "rottexc", "<font color=red>※ 开盘中禁止设置或变更自动走飞金额！</font>" );
    }
}
$tpl->set( "test", $test = true ? "20" : "14" );
$tpl->set( "amountlist", $list );
$tpl->set( "gametypeStr", $tblName );
$tpl->set( "gametype", $gametype );
$ui->header();
$ui->showNews3D( $curruser['acl'] );
$tpl->show( "main" );
$ui->footer();
?>